<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page language="java" import="java.lang.*" %>
<%@ page import = "java.sql.SQLException" %>
<%@ page import = "com.seniorproject.aims.*" %>
<%@ page import = "java.util.List" %>
<%@page import="java.util.ArrayList"%>
<%@ page import = "java.util.Properties" %>
<%@ page import = "javax.servlet.ServletContext" %>
<%@ page import = "java.io.File" %>
<%@ page import = "java.io.InputStream" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Student Edit</title>
<link rel="stylesheet" type="text/css" href="css/stylev2.css" />
<link rel="stylesheet" type="text/css" href="css/student-system.css" />
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<style type="text/css">
	a {
      text-decoration:none;
   }
</style>

<script>
$(document).ready(function(){

	 $("#result_div").hide();
	 
 	 $("button").click(function(){
 		 
 		 var name_in = document.getElementById("name_in").value;
 		 var id_in = document.getElementById("id_in").value;
 		 //var department_in = document.getElementById("department_in").value;
 		 //var year_in = document.getElementById("year_in").value;
 		 var select = document.getElementById("department_in");
		 var department_in = select.options[select.selectedIndex].value;		 
		 var select1 = document.getElementById("year_in");
		 var year_in = select1.options[select1.selectedIndex].value;
		
		 var patt = new RegExp("[#$%^*?=@-_+{}'\"()&|!~`<>]");
		 
		// alert("name:"+name_in+"|id:"+id_in+"|department:"+department_in+"|year:"+year_in);
		
		var name_temp = name_in.split(" ");
		//alert("name_temp.length  "+name_temp.length);//////////////////////////////////////
		if(name_temp.length >= 2) {
			alert("กรุณาใส่ชื่อให้ถูกต้อง");
 				return false;
		}
 		 
 		 var name_is_null = 1; //1 for null
 		 var id_is_null  = 1;
 		 var depart_is_null = 1;
 		 var year_is_null  = 1;
 		 
 		 if(name_in=="") {
 				 
 		 }else{
 			 if(name_in == parseInt(name_in,10)){
 				alert("กรุณาใส่ชื่อให้ถูกต้อง");
  				return false;
 			 }
			if(patt.test(name_in)) { 
				
				//alert("name");///////////////////////////////////////////////
				
				alert("กรุณาใส่ชื่อให้ถูกต้องค่ะ");
				return false;
			}
 			 name_is_null = 0;
 		 }
 		
 		 if(id_in==""){ 
 		 }else{
 			 if(!(id_in == parseInt(id_in,10))){
  				alert("กรุณาใส่ ID ให้ถูกต้อง");
   				return false;
  			 }
 			 id_is_null = 0;
 		 }
 		 
 		 if(department_in=="select"){
 			 
 		 }else{
 			
 			 depart_is_null = 0;
 		 }
 		 
 		 if(year_in=="select"){
 			 
 		 }else{
 			 
 	
 			 year_is_null = 0;
 		 }
 		 
 		
 		
 		 
 	//	 alert(name_is_null +""+ id_is_null +""+ depart_is_null +""+ year_is_null);
 		 if(name_is_null+id_is_null+depart_is_null+year_is_null==4)
 		{
 			 	alert("กรุณาใส่ keyword ค้นหา");		 
 			 	return false;
    	 }
 		
 		// alert("name:"+name_in+" id:"+id_in+" department:"+department_in+" year:"+year_in);
 		
 		var option = "";
 		option = name_is_null.toString()+id_is_null.toString()+depart_is_null.toString()+year_is_null.toString();
 		
 		var sql_con = ""; 
 		var name_con = "null";
 		var start_date_con ="X"; 
 		var start_date ;
		var date_now = new Date();
		var temp_year  = date_now.getFullYear();
		var temp_month = date_now.getMonth()+1;
		var year_high = false;
 		//alert("option is:"+option);
 		
		switch(option){
		case "0000":

			switch (year_in){
				case "1":
			
					if(temp_month<6)
					{
						start_date = temp_year-1;
					}else{
						start_date = temp_year ;  
					}
				break;
				
				case "2":
			
					if(temp_month<6){
						
						start_date = temp_year-2;
					}else{
						start_date = temp_year-1;
						
					}			
				break;
				
				case "3":
				
					if(temp_month<6){
						
						start_date = temp_year-3;
					}else{
						start_date = temp_year-2;
						
					}	
					
				break;
				
				case "4":
				
					if(temp_month<6){
						
						start_date = temp_year-4;
					}else{
						start_date = temp_year-3;
						
					}	
				break ;
				
				case "5":
					
					if(temp_month<6){
						
						start_date = temp_year-4;
					}else{
						start_date = temp_year-3;
						
					}
					
					year_high = true;
					
				break;
			}
			
			sql_con =  " AND S.student_id='"+id_in
			+"' AND D.department_id='"+department_in+"' AND S.start_date ";
		start_date_con = start_date;
		name_con = name_in;
				
		
			break;
		case "0001":
			sql_con =  " AND S.student_id='"+id_in
			+"' AND D.department_id='"+department_in+"'";
			name_con = name_in;
				
			break;
		case "0010":
				
				switch (year_in){
				case "1":
			
					if(temp_month<6)
					{
						start_date = temp_year-1;
					}else{
						start_date = temp_year ;  
					}
				break;
				
				case "2":
			
					if(temp_month<6){
						
						start_date = temp_year-2;
					}else{
						start_date = temp_year-1;
						
					}			
				break;
				
				case "3":
				
					if(temp_month<6){
						
						start_date = temp_year-3;
					}else{
						start_date = temp_year-2;
						
					}	
					
				break;
				
				case "4":
				
					if(temp_month<6){
						
						start_date = temp_year-4;
					}else{
						start_date = temp_year-3;
						
					}	
				break ;
				
				case "5":
					
					if(temp_month<6){
						
						start_date = temp_year-4;
					}else{
						start_date = temp_year-3;
						
					}
					
					year_high = true;
					
					
				break;
			}
				
				sql_con =  " AND S.student_id='"+id_in
			+"' AND S.start_date ";
			start_date_con = start_date;
			name_con = name_in;
	
			
			break;
		case "0011":
			sql_con =  " AND S.student_id='"+id_in+"'";
			name_con = name_in;
			
			break;
		case "0100":
				switch (year_in){
				case "1":
			
					if(temp_month<6)
					{
						start_date = temp_year-1;
					}else{
						start_date = temp_year ;  
					}
				break;
				
				case "2":
			
					if(temp_month<6){
						
						start_date = temp_year-2;
					}else{
						start_date = temp_year-1;
						
					}			
				break;
				
				case "3":
				
					if(temp_month<6){
						
						start_date = temp_year-3;
					}else{
						start_date = temp_year-2;
						
					}	
					
				break;
				
				case "4":
				
					if(temp_month<6){
						
						start_date = temp_year-4;
					}else{
						start_date = temp_year-3;
						
					}	
				break ;
				
				case "5":
					
					if(temp_month<6){
						
						start_date = temp_year-4;
					}else{
						start_date = temp_year-3;
						
					}
					
					year_high = true;
					
					
				break;
			}
				sql_con =  " AND D.department_id='"+department_in+"' AND S.start_date ";
			start_date_con = start_date;
			name_con = name_in;


			break;
		case "0101":
			sql_con =  " AND D.department_id='"+department_in+"'";
			name_con = name_in;
	
			break;
		case "0110":
			switch (year_in){
				case "1":
			
					if(temp_month<6)
					{
						start_date = temp_year-1;
					}else{
						start_date = temp_year ;  
					}
				break;
				
				case "2":
			
					if(temp_month<6){
						
						start_date = temp_year-2;
					}else{
						start_date = temp_year-1;
						
					}			
				break;
				
				case "3":
				
					if(temp_month<6){
						
						start_date = temp_year-3;
					}else{
						start_date = temp_year-2;
						
					}	
					
				break;
				
				case "4":
				
					if(temp_month<6){
						
						start_date = temp_year-4;
					}else{
						start_date = temp_year-3;
						
					}	
				break ;
				
				case "5":
					
					if(temp_month<6){
						
						start_date = temp_year-4;
					}else{
						start_date = temp_year-3;
						
					}
					
					year_high = true;
					
					
				break;
			}
			sql_con =  " AND S.start_date ";
			start_date_con = start_date;
			name_con = name_in;
			
		
			break;
		case "0111":
			name_con = name_in;

				break;
			case "1000":
				
 				switch (year_in){
					case "1":
				
						if(temp_month<6)
						{
							start_date = temp_year-1;
						}else{
							start_date = temp_year ;  
						}
					break;
					
					case "2":
				
						if(temp_month<6){
							
							start_date = temp_year-2;
						}else{
							start_date = temp_year-1;
							
						}			
					break;
					
					case "3":
					
						if(temp_month<6){
							
							start_date = temp_year-3;
						}else{
							start_date = temp_year-2;
							
						}	
						
					break;
					
					case "4":
					
						if(temp_month<6){
							
							start_date = temp_year-4;
						}else{
							start_date = temp_year-3;
							
						}	
					break ;
					
					case "5":
						
						if(temp_month<6){
							
							start_date = temp_year-4;
						}else{
							start_date = temp_year-3;
							
						}
						
						year_high = true;
						
						
					break;
				}
 				sql_con =  " AND S.student_id='"+id_in
				+"' AND D.department_id='"+department_in+"' AND S.start_date ";
				start_date_con = start_date;
				
				break;
			case "1001":
				sql_con =  " AND S.student_id='"+id_in
				+"' AND D.department_id='"+department_in+"'";

				break;
			case "1010":
				
 				switch (year_in){
					case "1":
				
						if(temp_month<6)
						{
							start_date = temp_year-1;
						}else{
							start_date = temp_year ;  
						}
					break;
					
					case "2":
				
						if(temp_month<6){
							
							start_date = temp_year-2;
						}else{
							start_date = temp_year-1;
							
						}			
					break;
					
					case "3":
					
						if(temp_month<6){
							
							start_date = temp_year-3;
						}else{
							start_date = temp_year-2;
							
						}	
						
					break;
					
					case "4":
					
						if(temp_month<6){
							
							start_date = temp_year-4;
						}else{
							start_date = temp_year-3;
							
						}	
					break ;
					
					case "5":
						
						if(temp_month<6){
							
							start_date = temp_year-4;
						}else{
							start_date = temp_year-3;
							
						}
						
						year_high = true;
						
						
					break;
				}
 				sql_con =  " AND S.student_id='"+id_in+"'"
				+" AND S.start_date ";
				start_date_con = start_date;


				break;
			case "1011":
				sql_con = " AND S.student_id='"+id_in+"'";

				break;
			case "1100":
				
 				switch (year_in){
					case "1":
				
						if(temp_month<6)
						{
							start_date = temp_year-1;
						}else{
							start_date = temp_year ;  
						}
					break;
					
					case "2":
				
						if(temp_month<6){
							
							start_date = temp_year-2;
						}else{
							start_date = temp_year-1;
							
						}			
					break;
					
					case "3":
					
						if(temp_month<6){
							
							start_date = temp_year-3;
						}else{
							start_date = temp_year-2;
							
						}	
						
					break;
					
					case "4":
					
						if(temp_month<6){
							
							start_date = temp_year-4;
						}else{
							start_date = temp_year-3;
							
						}	
					break ;
					
					case "5":
						
						if(temp_month<6){
							
							start_date = temp_year-4;
						}else{
							start_date = temp_year-3;
							
						}
						
						year_high = true;
						
						
					break;
				}
			sql_con = " AND D.department_id='"+department_in+"' AND S.start_date ";
			start_date_con = start_date;
		
				
				break;
			case "1101":
				sql_con = " AND D.department_id='"+department_in+"'";
				
				break;
			case "1110":

				switch (year_in){
					case "1":
				
						if(temp_month<6)
						{
							start_date = temp_year-1;
						}else{
							start_date = temp_year ;  
						}
					break;
					
					case "2":
				
						if(temp_month<6){
							
							start_date = temp_year-2;
						}else{
							start_date = temp_year-1;
							
						}			
					break;
					
					case "3":
					
						if(temp_month<6){
							
							start_date = temp_year-3;
						}else{
							start_date = temp_year-2;
							
						}	
						
					break;
					
					case "4":
					
						if(temp_month<6){
							
							start_date = temp_year-4;
						}else{
							start_date = temp_year-3;
							
						}	
					break ;
					
					case "5":
						
						if(temp_month<6){
							
							start_date = temp_year-4;
						}else{
							start_date = temp_year-3;
							
						}
						
						year_high = true;
						
						
					break;
				}
				sql_con = " AND S.start_date ";
				start_date_con = start_date;
				
			
				break;
		
		}
 		 var xmlhttp;
 		
 		if(window.XMLHttpRequest) {
 			// code for IE7+, Firefox, Chrome, Opera, Safari
 			xmlhttp = new XMLHttpRequest();
 		}
 		else {
 			// code for IE6, IE5
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		}
 		
 		xmlhttp.onreadystatechange = function() {
 			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {	
 			//	alert("I'm Back");//////////////////
 				
 				if($('#result_div').find('div').length > 0) {					
 					$('#result_div').find('div').remove();
 				}
 				
 				var jsonObj = JSON.parse(xmlhttp.responseText);
 				
 				//alert("I'm Back");
 				if(jsonObj.length == 0) {
 				//	massage();
 					alert("ไม่พบข้อมูล");
 				}
 				else{
 				//	alert("That work !!!");
 					
 					
 					head = '<div class="CSSTableGenerator">'
 							+ '<table  width="950" border="1" align="center" id="table_student">'
 							+ '<tr>'
 			              	+ '<td width="80"><center><strong>รหัสนักศึกษา</strong></center></td>'
 			              	+ '<td width="100"><center><strong>ชื่อ</strong></center></td>'
 			              	+ '<td width="130"><center><strong>นามสกุล</strong></center></td>'
 			              	+ '<td width="40"><center><strong></strong></center></td>'
 			              	+ '<td width="100"><center><strong>กรณีเปลี่ยนชื่อ</strong></center></td>'
 			              	+ '<td width="80"><center><strong>กรณีย้ายภาควิชา</strong></center></td>'
 			              	+ '</tr>';
 							
 					$('#result_div').append(head);
 				
 					for(i in jsonObj) {
 						if(i%2 == 0) { 
 							class_name = 'silvergrad';
 						}
 						else {
 							class_name = 'bluegrad';
 						}
 						
 						text = '<tr>'
 								+ '<td width="80"><center>'+jsonObj[i].studentId+'</center></td>'
 								+ '<td width="80"><center>'+jsonObj[i].nameTH+'</center></td>'
 								+ '<td width="80"><center>'+jsonObj[i].surnameTH+'</center></td>'
 								+ '<td width="80" class="'+class_name+'" onclick="to_student_edit_personal(\''+jsonObj[i].studentId+'\')"><center>ข้อมูลส่วนตัว</center></td>'
 								+ '<td width="80" class="'+class_name+'" onclick="to_student_edit_name(\''+jsonObj[i].studentId+'\')"><center>ชื่อ-นามสกุล</center></td>'
 								+ '<td width="80" class="'+class_name+'" onclick="to_student_edit_department(\''+jsonObj[i].studentId+'\')"><center>ภาควิชา</center></td>'
 								+ '</tr>';
 								
 						$('#table_student').append(text);
 					}
 					
 					$('#result_div').append('</table></div>');
 				}
 			
 			}// end if check state
 		}// end function
 		
 		//xmlhttp.open("POST", "student_search_background.jsp?user_input_search=" + user_search_input+"&option="+option_value, true);
 		//alert("sql_con:"+sql_con);	
		xmlhttp.open("POST", "student_search_background.jsp?sql_con="+sql_con+"&start_date_con="+start_date_con+"&name_con="+name_con+"&year_high="+year_high, true);
 		//
 		xmlhttp.send();
	  
	  $("#result_div").show();
  });
 
	 
});

function to_student_edit_name(id){
	
	  var form = document.createElement("form");
	      form.setAttribute("method", "post");
	      form.setAttribute("action", "student_edit_name.jsp");
	  var hiddenField = document.createElement("input");
	      hiddenField.setAttribute("type", "hidden");
          hiddenField.setAttribute("name", "student_id");
          hiddenField.setAttribute("id","student_id");
          hiddenField.setAttribute("value", id);
      var hiddenField2 = document.createElement("input");
	      hiddenField2.setAttribute("type", "hidden");
          hiddenField2.setAttribute("name", "checker");
          hiddenField2.setAttribute("id","checker");
          hiddenField2.setAttribute("value", "NONE");
          
      form.appendChild(hiddenField);
      form.appendChild(hiddenField2);
      
      document.body.appendChild(form);
      form.submit();
	
	
}

function to_student_edit_personal(id){
	
	  var form = document.createElement("form");
  	      form.setAttribute("method", "post");
    	  form.setAttribute("action", "student_edit_personal.jsp");
 	  var hiddenField = document.createElement("input");
          hiddenField.setAttribute("type", "hidden");
          hiddenField.setAttribute("name", "student_id");
          hiddenField.setAttribute("id","student_id");
          hiddenField.setAttribute("value", id);
       form.appendChild(hiddenField);
  
  document.body.appendChild(form);
  form.submit();
	
}

function to_student_edit_department(id){
	
	  var form = document.createElement("form");
          form.setAttribute("method", "post");
      	  form.setAttribute("action", "student_edit_department.jsp");
  	  var hiddenField = document.createElement("input");
          hiddenField.setAttribute("type", "hidden");
          hiddenField.setAttribute("name", "student_id");
          hiddenField.setAttribute("id","student_id");
          hiddenField.setAttribute("value", id);
  form.appendChild(hiddenField);
  
  document.body.appendChild(form);
  form.submit();
	
}

</script>

	
<style>

	.silvergrad  {
	    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFF', endColorstr='#CCC');
	    background: -webkit-gradient(linear, left top, left bottom, from(#FFF), to(#CCC));
	    background: -moz-linear-gradient(top, #FFF, #CCC);
	}
	.silvergrad:hover  {
	    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#999', endColorstr='#CCC');
	    background: -webkit-gradient(linear, left top, left bottom, from(#999), to(#CCC));
	    background: -moz-linear-gradient(top, #999, #CCC);
	    cursor: pointer;
	}
	
	.bluegrad  {
	    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#c9e3fd', endColorstr='#aad4ff');
	    background: -webkit-gradient(linear, left top, left bottom, from(#c9e3fd), to(#aad4ff));
	    background: -moz-linear-gradient(top, #c9e3fd, #aad4ff);
	}
	.bluegrad:hover  {
	    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#85b7eb', endColorstr='#cae1f8');
	    background: -webkit-gradient(linear, left top, left bottom, from(#85b7eb), to(#cae1f8));
	    background: -moz-linear-gradient(top, #85b7eb, #cae1f8);
	    cursor: pointer;
	}
</style>

</head>
<body>

<%	
		String strUser = String.valueOf(session.getAttribute("sUser"));
		HttpSession htp_session = request.getSession();
				
		if (htp_session == null || htp_session.getAttribute("sUser") == null) {
		    // Forward the control to login.jsp if authentication fails or session expires
		    request.getRequestDispatcher("/login.jsp").forward(request,
		        response);
		}
		
		if("admin".equals(htp_session.getAttribute("sUser"))){%>
		<script>alert("This user dont have PERMISSION to access this zone.");</script>
		<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=admin_home.jsp"> 	
		<%}
		
//////////get permission ///////////
		
		String name = String.valueOf(session.getAttribute("name"));
		String surname = String.valueOf(session.getAttribute("surname"));
		String role_name = String.valueOf(session.getAttribute("student_role"));
		
		String department_id2 = String.valueOf(session.getAttribute("department_id"));
		
		System.out.println("name : " + name);///////////////////////////////
		System.out.println("department_id : " + department_id2);/////////////////////////
		
		
		List<String> system_name = new ArrayList<String>();
		
		Permission permission = new Permission(strUser,name);
		permission.setDepartmentId(department_id2);
		permission.setStudentCreate(Boolean.valueOf(String.valueOf(session.getAttribute("student_create"))));
		permission.setStudentDelete(Boolean.valueOf(String.valueOf(session.getAttribute("student_delete"))));
		permission.setStudentRead(Boolean.valueOf(String.valueOf(session.getAttribute("student_read"))));
		permission.setStudentUpdate(Boolean.valueOf(String.valueOf(session.getAttribute("student_update"))));
		
		String permiss = "";
		if(permission.getStudentCreate()) {
			permiss = permiss + "Add";
		}
		if(permission.getStudentUpdate()) {
			if("".equals(permiss)) {
				permiss = permiss + "Edit";
			} else {
				permiss = permiss + " Edit";
			}
		}
		if(permission.getStudentRead()) {
			if("".equals(permiss)) {
				permiss = permiss + "Read";
			} else {
				permiss = permiss + " Read";
			}
		}
		if(permission.getStudentDelete()) {
			if("".equals(permiss)) {
				permiss = permiss + "Delete";
			} else {
				permiss = permiss + " Delete";
			}
		}
		//check permission
		if(!permission.getStudentUpdate()){%>
			<script>alert("This user dont have PERMISSION to access this zone.");</script>
			<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=student_home.jsp"> 	
		<%}
		
		
		//set Database Connection
		String hostProps = "";
		String usernameProps  = "";
		String passwordProps  = "";
		String databaseProps = "";
		
		try {
			//get current path
			ServletContext servletContext = request.getSession().getServletContext();
			
			InputStream input = servletContext.getResourceAsStream("/properties/connectDB.properties");
			Properties props = new Properties();
			
			props.load(input);
		
			hostProps  = props.getProperty("host");
			usernameProps  = props.getProperty("username");
			passwordProps  = props.getProperty("password");
			databaseProps = props.getProperty("database");
		} catch (Exception e) { 
			out.println(e);  
		}
		
		// connect database
		Connection connect = null;		
		try {
			Class.forName("com.mysql.jdbc.Driver");
		
			connect =  DriverManager.getConnection("jdbc:mysql://" + hostProps  + "/" + databaseProps +
					"?user=" + usernameProps  + "&password=" + passwordProps + "&characterEncoding=tis620" );
		
			if(connect != null){
				System.out.println("Database Connect Sucesses.");
			} else {
				System.out.println("Database Connect Failed.");	
			}
		
		} catch (Exception e) {
			out.println(e.getMessage());
			e.printStackTrace();
		}
		
		
		/* find department in database */
		List<Department> department = new ArrayList<Department>();
		System.out.println("@student_edit department_id:"+permission.getDepartment_id());
		
		try {		
			ResultSet rs_department;
			if(("0").equals(permission.getDepartment_id()))
			{
				  rs_department = connect.createStatement().executeQuery("SELECT department_id, department_name_th " 
							+ " FROM department " + " ORDER BY department_id");
			}
			else{
				  rs_department = connect.createStatement().executeQuery("SELECT department_id, department_name_th " 
							+ " FROM department " 
						    +" WHERE department_id="+permission.getDepartment_id()
						    );
			}
		  
			
			while(rs_department.next()) {
				Department dep = new Department();
				
				dep.setDepartmentNameTH(rs_department.getString("department_name_th"));
				dep.setDepartmentId(Integer.parseInt(rs_department.getString("department_id")));
				
				department.add(dep);
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		connect.close();
%>

<div id="page-wrap">
		<div id="inside">
			<table border="0">
				<tr style="font-size:24px">
					<td width="600" height="100" style= "background-color: #273b80;border: 0px ;padding: 0px; 0px;" >
						<div id="header_banner-2"></div>
					</td>
					
					<td width="680" height="100" style= "background-color: #273b80;border: 0px;padding: 0px; 0px;" >
						<p align="right"><label><font size="4" color="#ffffff">username : <%=strUser%>&nbsp;&nbsp;</font></label></p>
						<a href="logout.jsp"><p align="right"><label style="cursor: pointer;"><font size="3" color="#ffffff">log out &nbsp;</font></label></p></a>
					</td>
				</tr>
			</table>
			<table border="0">
				<tr style="font-size:10px">
					<td width = "720" height="50" style= "background-color:#D0D0D0 ;">
						<center><a href="student_home.jsp"><h2><font color="#273b80"><label style="cursor: pointer;">หน้าแรก</label></font></h2></a></center>
					</td>
	<%
			if(permission.getStudentRead()) {
	%>
					<td width = "720" height="50" style= "background-color:#D0D0D0 ;">
						<center><a href="student_search.jsp"><h2><font color="#273b80"><label style="cursor: pointer;">ค้นหา</label></font></h2></a></center>
					</td>
					<td width = "720" height="50" style= "background-color:#D0D0D0 ;">
						<center><a href="student_summary.jsp"><h2><font color="#273b80"><label style="cursor: pointer;">สรุปจำนวนนักศึกษา</label></font></h2></a></center>
					</td>
	<%
			}
			if(permission.getStudentCreate()) {
	%>
					<td width = "720" height="50" style= "background-color:#D0D0D0 ;">
						<center><a href="student_add.jsp"><h2><font color="#273b80"><label style="cursor: pointer;">เพิ่มนักศึกษา</label></font></h2></center>
					</td>
	<%
			}
			
			if(permission.getStudentUpdate()) {
	%>
					<td width = "720" height="50" style= "background-color:#FFFFFF ; border-bottom-color: #FFFFFF; border-right-color: #FFFFFF">
						<center><a href=""><h2><font color="#273b80"><label>แก้ไขข้อมูล</label></font></h2></a></center>
					</td>
	<%
			}
	%>
				</tr>
			</table>
			
				<div id="main-content-ac">
				
			<!-- 		<h2 style="padding-left: 2.5cm; color: #273b80;">ค้นหา</h2>	 -->
					
					<!--
					  	
						<center>
					 	 <input type="text" name="search_box" id="search_box" style="height: 25px; width: 400px; font-size:medium;">
					  			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button style="height: 25px; width: 80px; font-size: medium; ">Search</button>
					  			<br><br>
					  	</center>
					  	<div style="float: right; padding-right:350px; font-size:15px;" >
						  	<input type="radio" name="option" id="option" value="name"> ชื่อ &nbsp;
						  	<input type="radio" name="option" id="option" value="id">   รหัสนักศึกษา &nbsp;
						  	<input type="radio" name="option" id="option" value="department">   ภาควิชา
					  	</div>
					  	<br><br><br><br>
					  	
						
					  -->
					  <div style="font-size:15px;">
					  
					  	<br>
					  	<center>
							 <font size="5"> ชื่อ <input type="text" name="name_in" id="name_in" style="font-size:15px;"></font>
							 <font size="5"> &nbsp; รหัสนักศึกษา<input type="text" name="id_in" id="id_in" maxlength="7" style="font-size:15px;"></font>
						  			
							 <font size="5"> &nbsp; ภาควิชา <select name="department_in" id="department_in" style="font-size:15px;">
							  		<!--    		<option value="select">Select</option> 	-->
<%
									for(Department dept : department) {
										if(dept.getDepartmentId() == 0) {
									%>
											<option value="select">Select</option>
									<% 
										}
										else {
									
%>
										<option value="<%=dept.getDepartmentId()%>" id="<%=dept.getDepartmentId()%>"><%=dept.getDepartmentNameTH()%></option>	
<%											
										}
									}
%>
									</select></font>
									
							  <font size="5"> &nbsp; ชั้นปี <select name="year_in" id="year_in" style="font-size:15px;">
							  			<option value="select">Select</option>
							  			<option value="1"> 1 </option>
							  			<option value="2"> 2 </option>
							  			<option value="3"> 3 </option>
							  			<option value="4"> 4 </option>
							  			<option value="5"> ปีสูง </option>
							  	   </select> </font>
							 <br>
							 <br>
							 <button style="height: 25px; width: 80px; font-size: medium; ">ค้นหา</button>
							 <br><br>							 
						</center>
				  	  </div>
				  	
			
				  	<center><div id="result_div">
				
			
						

    			    </div></center>	
    			    						
					<br><br><br><br><br><br><br><br><br><br><br><br><br>
						
				
				
			<div style="clear: both;"></div>
				
			<div id="footer"></div>
			
		</div>		
			<div style="clear: both;"></div>		
   </div>


</body>
</html>